﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace WellDone
{
    public sealed partial class MercuryHostedCheckoutDialog : Page
    {
        public event EventHandler CloseRequested;
        public bool bUpdated = false;
        public string strServiceAddress;
        public decimal total = 0;
        public int invoice = 0;

        public MercuryHostedCheckoutDialog()
        {
            this.InitializeComponent();
        }
        public async void init()
        {
            ServiceReferenceMercuryHostedCheckout.InitPaymentRequest req = new ServiceReferenceMercuryHostedCheckout.InitPaymentRequest();
            ServiceReferenceMercuryHostedCheckout.InitializePaymentResponse resp = new ServiceReferenceMercuryHostedCheckout.InitializePaymentResponse();
            req.TranType = "PreAuth";
            req.Memo = "OpenRPOS v1.0";
            req.TotalAmount = (double)total;// 1.23;
            req.Invoice = invoice.ToString();
            req.Frequency = "OneTime";
            req.ProcessCompleteUrl = "http://openrpos.com/contact.html";
            req.ReturnUrl = "http://openrpos.com/contact.html";
            req.DefaultSwipe = "Manual";
            req.CardEntryMethod = "Manual";
            req.Keypad = "On";
            req.OperatorID = "test";
            //req.PartialAuth = (cbPartial.IsChecked == true) ? "on" : "off";
            resp = await Globals.mercuryHostedCheckoutClient.InitializePaymentAsync(req);
            // Load the page
            wvMain.Navigate(new Uri("https://hc.mercurydev.net/CheckoutPOSiFrame.aspx?pid=" + resp.Body.InitializePaymentResult.PaymentID));
        }
        private void pane_Showing(InputPane sender, InputPaneVisibilityEventArgs e)
        {
            // Shift the dialog up...
            this.RootPanel.Margin = new Thickness(0, -1 * e.OccludedRect.Y, 0, 0);
        }
        private void pane_Hiding(InputPane sender, InputPaneVisibilityEventArgs e)
        {
            // Restore...
            this.RootPanel.Margin = new Thickness(0, 0, 0, 0);
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            // Close the dialog
            if (this.CloseRequested != null)
            {
                this.CloseRequested(this, EventArgs.Empty);
            }
        }
    }
}
